package cn.tedu.imop.marketing.dao.repository.impl;

import cn.tedu.imop.common.context.PageContext;
import cn.tedu.imop.common.pojo.PageData;
import cn.tedu.imop.common.utils.PageInfoToPageDataConverter;
import cn.tedu.imop.marketing.dao.mapper.MemberCouponMapper;
import cn.tedu.imop.marketing.dao.repository.MemberCouponRepository;
import cn.tedu.imop.marketing.entity.MemberCoupon;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class MemberCouponRepositoryImpl implements MemberCouponRepository {

    private final MemberCouponMapper memberCouponMapper;
    public MemberCouponRepositoryImpl(MemberCouponMapper memberCouponMapper) {
        this.memberCouponMapper = memberCouponMapper;
    }

    @Override
    public int insertMemberCoupon(MemberCoupon memberCoupon) {
        return memberCouponMapper.insert(memberCoupon);
    }

    @Override
    public MemberCoupon selectMemberCouponById(Integer id) {
        return memberCouponMapper.selectById(id);
    }

    @Override
    public PageData<MemberCoupon> selectList(Integer memberId, Integer status) {
        PageContext.startPage();
        List<MemberCoupon> memberCoupons =
                memberCouponMapper.selectList(memberId, status);
        return PageInfoToPageDataConverter.convert(new PageInfo<>(memberCoupons));
    }

    @Override
    public int updateMemberCoupon(MemberCoupon memberCoupon) {
        return memberCouponMapper.update(memberCoupon);
    }

    @Override
    public int countMemberCoupon(Integer memberId, Integer couponId, String couponCode) {
        return memberCouponMapper.countMemberCoupon(memberId, couponId, couponCode);
    }
}
